import { dialog } from "electron";
import {hkcu} from 'regkey'

const openFile = async ()=>{
    // 处理文件选择请求
    const result = await dialog.showOpenDialog({
        properties: ['openFile'],
        title: '选择文件',
        filters: [
            { name: '所有文件', extensions: ['*'] }
        ]
    })

    if (!result.canceled && result.filePaths.length > 0) {
        return result.filePaths[0]; // 返回完整文件路径
    }
    return null
}

const openFolder = async()=>{
    const result = await dialog.showOpenDialog({
        properties: ['openDirectory'],
        filters: [
            { name: '所有文件', extensions: ['*'] }
        ]
    })

    if(!result.canceled && result.filePaths.length > 0){
        return result.filePaths[0]; // 返回完整文件路径
    }

    return null
}

const getSteamPath = ()=>{
    const ms = hkcu.openSubKey('Software/Valve/Steam')
    if(!ms){
      console.log('打开注册表失败');
      return null
    }
    const steamPath = ms.getStringValue('SteamPath')
    const commonPath = steamPath+'/steamapps/common'
    console.log(commonPath)
    return commonPath
  }

export {
    openFile,
    openFolder,
    getSteamPath
}